/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wakawakathistimeforafrica.tools;

import java.util.Enumeration;
import weka.classifiers.Classifier;
import weka.classifiers.Evaluation;
import weka.classifiers.bayes.NaiveBayes;
import weka.core.Instance;
import weka.core.Instances;

/**
 *
 * @author Jissay
 */
public class ModelGenerator {
    
    private Classifier cModel;
    private Instances instancesSet;
    
    /**
     * Constructor
     */
    public ModelGenerator() {
        this.cModel = (Classifier) new NaiveBayes();
    }
    
    /**
     * Generate model from arff file with ArffReader returning a Instances class.
     * @throws Exception 
     */
    public void generateModel() throws Exception {
        // Get instances from arff file
        ArffReader arffReader = new ArffReader();
        this.instancesSet = arffReader.getData();
        
        // Cleaning dataset
        int numInst = this.instancesSet.numInstances();
        for (int current = 0; current < numInst; current++) {
            Instance currentInstance = this.instancesSet.instance(current);
            for (int i = 0; i < 21; i++) {
                if (currentInstance.isMissing(currentInstance.attribute(i))) {
                    this.instancesSet.delete(current);
                    i=21;
                    System.out.println("Delete instance");
                }
            }
        }
        
        // Build Model
        this.cModel.buildClassifier(this.instancesSet);
        
        // Model evaluation
        Evaluation eTest = new Evaluation(this.instancesSet);
        eTest.evaluateModel(this.cModel, this.instancesSet);
        
        String strSummary = eTest.toSummaryString();
        System.out.println(strSummary);
    }

    
    
    public Classifier getcModel() {
        return cModel;
    }

    public void setcModel(Classifier cModel) {
        this.cModel = cModel;
    }

    public Instances getInstancesSet() {
        return instancesSet;
    }

    public void setInstancesSet(Instances instancesSet) {
        this.instancesSet = instancesSet;
    }
    
}
